<template>
  <div id="cluereport">
    <el-dialog
      title="变更内容"
      :visible.sync="dialogVisible"
      width="1200px" :close-on-click-modal="false" :close-on-press-escape="false">
      <section class="wboxd" style="width:1140px">
        <el-table :data="logdetails" highlight-current-row border v-loading="detailsLoading" empty-text='无变更'
          >
          <el-table-column prop="field" label="字段名称">
          </el-table-column>
          <el-table-column prop="before" label="变更前" width="480">
            <template slot-scope="scope">
              <template v-if="scope.row.field==='反映问题分类二'">
                <div>{{disciplineClassName(scope.row.before)}}</div>
              </template>
              <template v-else-if="scope.row.field==='涉及人员'">
                <div v-html='formatObj(scope.row.before)'></div>
              </template>
              <template v-else>
                <div>{{scope.row.before}}</div>
              </template>
            </template>
          </el-table-column>
          <el-table-column prop="after" label="变更后" width="480">
            <template slot-scope="scope">
              <template v-if="scope.row.field==='反映问题分类二'">
                <div v-html='disciplineClassName(scope.row.after)'></div>
              </template>
              <template v-else-if="scope.row.field==='涉及人员'">
                <div v-html='formatObj(scope.row.after)'></div>
              </template>
              <template v-else>
                <div>{{scope.row.after}}</div>
              </template>
            </template>
          </el-table-column>
        </el-table>
      </section>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item>干部监督</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/cluereport' }">线索举报</el-breadcrumb-item>
      <el-breadcrumb-item>操作日志</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxd">
    <!--工具条-->
      <h1>线索举报 操作日志</h1>
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border
        >
        <el-table-column type="index" label="序号" width="80" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column prop="operateType" label="操作类型" width="200">
          <template slot-scope="scope">
            {{operateTypeName(scope.row.operateType)}}
          </template>
        </el-table-column>
        <el-table-column prop="operateUserName" label="操作用户" width="200">
        </el-table-column>
        <el-table-column prop="dataCreateDatetime" label="操作时间">
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="primary" @click="detail(scope.row.id)" style="margin:10px 0">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination style="float:right" :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      disciplineClassDic: [],
      detailsLoading: false,
      logdetails: [],
      dialogVisible: false,
      listLoading: false,
      tableHeight: 100,
      list: [],
      pageNum: 1,
      pageSize: 20,
      totalnum: 0,
      keys: [
        {key: 'source', name: '来源'},
        {key: 'source', name: '来源'}
      ]
    }
  },
  methods: {
    disciplineClassName (str) {
      // if (arr === this.noRoleCode) { return this.noRoleText }
      if (str) {
        let arr = JSON.parse(str)
        let label = ''
        for (let item of arr) {
          if (item !== arr[0]) {
            label = label + '<br>'
          }
          for (let it of item) {
            if (it === item[0]) {
              label = label + this.disciplineClass2Name(it)
            } else {
              label = label + ' > ' + this.disciplineClass2Name(it)
            }
          }
        }
        return label
      }
    },
    disciplineClass2Name (code) {
      for (let item of this.disciplineClassDic) {
        if (item.value === code) {
          return item.label
        }
        if (item.children) {
          for (let it of item.children) {
            if (it.value === code) {
              return it.label
            }
          }
        }
      }
    },
    getDics () {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/sysDict/getByCode?code=14`)
        .then(response => {
          if (response.data.success) {
            this.disciplineClassDic = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    formatObj (obj) {
      if (obj) {
        if (typeof obj === 'string') {
          return obj
        } else if (typeof obj === 'object') {
          let str = ''
          for (let i = 0; i < obj.length; i++) {
            str = str + `单位：${obj[i].unit} 姓名：${obj[i].name}(${obj[i].idCardNo}) 职务：${obj[i].job}<br>`
          }
          return str
        } else {
          if (obj) {
            return '是'
          }
        }
      } else {
        if (obj === 0) {
          return '否'
        }
      }
    },
    operateTypeName (id) {
      switch (id) {
        case 1:
          return '新增'
        case 2:
          return '修改'
        case 3:
          return '删除'
      }
    },
    detail (id) {
      this.dialogVisible = true
      this.detailsLoading = true
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/busClueReportLog/getComparison?id=${id}`)
        .then(response => {
          this.detailsLoading = false
          if (response.data.success) {
            this.logdetails = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.detailsLoading = false
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    getList () {
      let para = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(this.$http.defaults.selectionAPI + `api/busClueReportLog/queryLog`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.list = response.data.result.records
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 220
      })
    }
  },
  mounted () {
    this.getList()
    this.getDics()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
